<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="referrer" content="no-referrer-when-downgrade">
    

    <title>Flutter音频识别 | 早起的年轻人</title>
    <meta property="og:title" content="Flutter音频识别 - 早起的年轻人">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2021-08-21T10:19:18&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2021-08-21T10:19:18&#43;08:00'>
        
    <meta name="Keywords" content="Flutter，golang,go语言,go语言笔记,飞雪无情,java,android,博客,项目管理,python,软件架构,公众号,小程序">
    <meta name="description" content="Flutter音频识别">
        
    <meta name="author" content="luckly">
    <meta property="og:url" content="https://luckly.work/post/flutter_tips/Flutter%E9%9F%B3%E9%A2%91%E8%AF%86%E5%88%AB/">
    <link rel="shortcut icon" href='/favicon.ico'  type="image/x-icon">

    <link rel="stylesheet" href='/css/normalize.css'>
    <link rel="stylesheet" href='/css/style.css'>
    <script type="text/javascript" src="//cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    
    
        <link href="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet">
    
    
    
    
        <link rel="stylesheet" href='/css/douban.css'>
    
        <link rel="stylesheet" href='/css/other.css'>
    
</head>

<link rel="stylesheet"
      href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js"></script>
<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://luckly.work/">
                        早起的年轻人
                    </a>
                
                <p class="description">专注于Flutter、Android、Java、Go语言(golang)、移动互联网、项目管理、软件架构</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://luckly.work/">首页</a>
                    
                    <a  href="https://luckly.work/categories/" title="分类">分类</a>
                    
                    <a  href="https://luckly.work/tags/" title="标签">标签</a>
                    
                    <a  href="https://luckly.work/archives/" title="归档">归档</a>
                    
                    <a  href="https://luckly.work/about/" title="关于我">关于我</a>
                    
                    <a  href="https://github.com/ITmxs/" title="github">github</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents"></nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">Flutter音频识别</h1>
        </header>
        <date class="post-meta meta-date">
            2021年8月21日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='/categories/Flutter'>Flutter</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <blockquote>
<p>本文主要介绍</p>
</blockquote>
<p><a href="https://carolinamalbuquerque.medium.com/audio-recognition-using-tensorflow-lite-in-flutter-application-8a4ad39964ae">https://carolinamalbuquerque.medium.com/audio-recognition-using-tensorflow-lite-in-flutter-application-8a4ad39964ae</a></p>
<p>机器学习 (ML) 和人工智能 (AI) 增强了移动应用程序的开发。将 ML 模型集成到应用程序中以对事件进行分类或预测，可以创建能够理解和识别用户行为的应用程序，并使他们的体验更加智能和有趣。一个易于理解的示例是根据在发送短信时键入的先前内容向用户建议的下一个单词。因此，本文将分析将 ML 模型集成到移动 Flutter 应用程序中以进行音频识别。</p>
<h1 id="创建分类模型">创建分类模型</h1>
<p>首先的，它需要有一个训练有素的分类模型。例如，如果您是 ML 概念的初学者，Google Teachable Machine 是创建模型的一种快速简便的方法。该框架提供了三种项目类型的创建：图像、音频和姿势。在此示例中，将使用 Google Teachable Machine (GTM) 模型，由于主要目标是集成音频分类模型，因此必须选择音频项目。</p>
<p>创建模型的第一步是将数据安排到不同的类中。可以立即记录样本或上传文件。每个类都有最少数量的音频样本。背景噪声是一个默认类，它必须包含带有背景噪声的样本。在此示例中，创建了<strong>Bell</strong>、<strong>Whistle</strong>和**Xylophone 类，**其中包含这些声音的音频样本。</p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/60/1*8hs87nyY1eVYbYCRm7gZgw.png?q=20">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/60/1*8hs87nyY1eVYbYCRm7gZgw.png?q=20" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/700/1*8hs87nyY1eVYbYCRm7gZgw.png">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/700/1*8hs87nyY1eVYbYCRm7gZgw.png" />
        </a>
    </p>
<p>使用 Google Teachable Machine 创建分类模型</p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/60/1*yWW1LYBA_bZ_MDPzEOIf_Q.png?q=20">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/60/1*yWW1LYBA_bZ_MDPzEOIf_Q.png?q=20" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/500/1*yWW1LYBA_bZ_MDPzEOIf_Q.png">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/500/1*yWW1LYBA_bZ_MDPzEOIf_Q.png" />
        </a>
    </p>
<p>将训练好的模型导出为 Tensorflow Lite 模型</p>
<p>数据按类分离后，必须<strong>训练</strong>模型并<strong>导出为 Tensorflow Lite 格式</strong>。下载的模型包含两个文件：(<code>labels.txt</code>指定类的标签)和<code>soundclassifier.tflite</code>(模型)。这些文件将被添加到移动应用程序中，以便在 tensorflow 的帮助下可以读取它们并加载模型。</p>
<p>**注意：**如果您对 ML 概念感到满意，我建议您开发自己的模型并对其进行训练，因为在您的应用程序中使用 GTM 模型可以提高其大小。Tensorflow 文档有一个帮助创建模型的<a href="https://www.tensorflow.org/tutorials/audio/simple_audio">指南</a>。</p>
<p>创建了一个简单的应用程序，其中包含文本小部件和用于开始录制音频的 MaterialButton。</p>
<p>我在这里留下了<code>main.dart</code>基本代码：</p>
<h1 id="创建flutter-应用程序">创建flutter 应用程序</h1>
<p>创建了一个简单的应用程序，其中包含文本小部件和用于开始录制音频的 MaterialButton。</p>
<p>我在这里留下了<code>main.dart</code>基本代码：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-dart" data-lang="dart"><span style="color:#66d9ef">import</span> <span style="color:#e6db74">&#39;package:flutter/material.dart&#39;</span>;
<span style="color:#66d9ef">import</span> <span style="color:#e6db74">&#39;package:tflite_audio/tflite_audio.dart&#39;</span>;

<span style="color:#66d9ef">void</span> main() {
  runApp(MyApp());
}

<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">MyApp</span> <span style="color:#66d9ef">extends</span> StatelessWidget {
  <span style="color:#75715e">// This widget is the root of your application.
</span><span style="color:#75715e"></span>  <span style="color:#960050;background-color:#1e0010">@</span>override
  Widget build(BuildContext context) {
    <span style="color:#66d9ef">return</span> MaterialApp(
      title: <span style="color:#e6db74">&#39;Flutter Demo&#39;</span>,
      theme: ThemeData.dark(),
      home: MyHomePage(),
    );
  }
}

<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">MyHomePage</span> <span style="color:#66d9ef">extends</span> StatefulWidget {
  <span style="color:#960050;background-color:#1e0010">@</span>override
  _MyHomePageState createState() <span style="color:#f92672">=&gt;</span> _MyHomePageState();
}

<span style="color:#66d9ef">class</span> <span style="color:#a6e22e">_MyHomePageState</span> <span style="color:#66d9ef">extends</span> State<span style="color:#f92672">&lt;</span>MyHomePage<span style="color:#f92672">&gt;</span> {
  <span style="color:#66d9ef">String</span> _sound <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Press the button to start&#34;</span>;
  <span style="color:#66d9ef">bool</span> _recording <span style="color:#f92672">=</span> <span style="color:#66d9ef">false</span>;

  <span style="color:#960050;background-color:#1e0010">@</span>override
  Widget build(BuildContext context) {
    <span style="color:#66d9ef">return</span> Scaffold(
      body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(<span style="color:#e6db74">&#34;assets/background.jpg&#34;</span>),
            fit: BoxFit.cover,
          ),
        ),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <span style="color:#f92672">&lt;</span>Widget<span style="color:#f92672">&gt;</span>[
              Container(
                padding: EdgeInsets.all(<span style="color:#ae81ff">20</span>),
                child: Text(
                  <span style="color:#e6db74">&#34;What&#39;s this sound?&#34;</span>,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: <span style="color:#ae81ff">60</span>,
                    fontWeight: FontWeight.w200,
                  ),
                ),
              ),
              MaterialButton(
                onPressed: (){},
                color: _recording <span style="color:#f92672">?</span> Colors.grey <span style="color:#f92672">:</span> Colors.pink,
                textColor: Colors.white,
                child: Icon(Icons.mic, size: <span style="color:#ae81ff">60</span>),
                shape: CircleBorder(),
                padding: EdgeInsets.all(<span style="color:#ae81ff">25</span>),
              ),
              Text(
                <span style="color:#e6db74">&#39;</span><span style="color:#e6db74">$</span>_sound<span style="color:#e6db74">&#39;</span>,
                style: Theme.of(context).textTheme.headline5,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
</code></pre></div><h1 id="将模型集成到应用程序中">将模型集成到应用程序中</h1>
<p>为了在移动应用程序中集成 tensorflow 模型，Tensorflow Lite 框架有助于在移动设备上运行这些模型。为了访问 Tensorflow Lite，为此需要一个<strong>flutter 插件</strong>：<a href="https://pub.dev/packages/tflite"><strong>tflite</strong></a>。但是，tflite 插件还没有分析音频。因此，将使用类似的最新插件进行音频处理：<a href="https://pub.dev/packages/tflite_audio"><strong>tflite_audio</strong></a>。除了这个插件支持 GTM 模型和带有解码波形输入的模型外，它还有一些文档中描述的限制，即只有在物理移动设备上运行时才有效。在结论中，将更详细地讨论这个主题。</p>
<p>首先，在您的<code>pubspec.yaml</code>文件中添加以下依赖项：</p>
<pre><code>dependencies:
	tflite_audio: ^0.1.5+3
</code></pre><p>要安装软件包，请运行：</p>
<pre><code>flutter pub get
</code></pre><p>创建一个新<code>/assets</code>目录，添加从 Google Teachable Machine 框架下载的<code>soundclassifier.tflite</code>和<code>labels.txt</code>文件，并更改项目中<code>pubspec.yaml</code>包含<code>/assets</code>文件夹的配置。</p>
<pre><code>flutter:
  # To add assets to your application, add an assets section:
  assets:
    - assets/labels.txt
    - assets/soundclassifier.tflite
</code></pre><p>之后需要配置Android和iOS环境，使用GTM模型需要选择tensorflow算子。</p>
<h1 id="安卓配置">安卓配置</h1>
<ol>
<li>将以下<strong>权限</strong>添加到<code>AndroidManifest.xml</code>：</li>
</ol>
<pre><code>&lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
</code></pre><p>2.将<strong>aaptOptions</strong>添加到<code>app/build.gradle</code>文件中：</p>
<pre><code>android {
   (...)
    aaptOptions {
        noCompress 'tflite'
    }
    lintOptions {
        disable 'InvalidPackage'
    }
(...)
}
</code></pre><p>3.在文件中启用<strong>选择操作</strong><code>app/build.gradle</code>：</p>
<pre><code>dependencies {
    implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
    implementation &quot;org.tensorflow:tensorflow-lite-select-tf-ops:+&quot;
}
</code></pre><p>4.更改<strong>的minSdkVersion</strong>到<strong>至少21</strong>的<code>app/build.gradle</code>文件。</p>
<h1 id="ios-配置">iOS 配置</h1>
<p>将以下权限添加到<code>ios/Runner/Info.plist</code>：</p>
<pre><code>&lt;key&gt;NSMicrophoneUsageDescription&lt;/key&gt;
&lt;string&gt;Record audio for playback&lt;/string&gt;
</code></pre><p>有必要将目标部署更改<strong>为</strong> <strong>至少 12.0</strong>。例如，打开<code>iOS/Runner.xcworkspace</code>XCode，选择<strong>Runner</strong>并在<strong>Info</strong>选项卡中更改 iOS 部署目标：</p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/freeze/max/60/1*nK3YABQqtiw-qggB__Ay4g.gif?q=20">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/freeze/max/60/1*nK3YABQqtiw-qggB__Ay4g.gif?q=20" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/700/1*nK3YABQqtiw-qggB__Ay4g.gif">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/700/1*nK3YABQqtiw-qggB__Ay4g.gif" />
        </a>
    </p>
<p>将 iOS 部署目标更改为 12.0</p>
<p>现在，您需要在中指定 iOS 目标部署 <code>ios/Runner/Podfile</code></p>
<pre><code>platform :ios, '12.0'
</code></pre><p>由于模型是 GTM 模型，<code>pod 'TensorFlowLiteSelectTfOps'</code>在目标中添加行<code>ios/Runner/Podfile</code></p>
<pre><code>target 'Runner' do
  use_frameworks!
  use_modular_headers!
  pod 'TensorFlowLiteSelectTfOps'
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
</code></pre><p>之后，在 XCode 上打开项目，选择<strong>Targets &gt; Runner &gt; Build Settings &gt; All</strong>并将以下行添加到<strong>Linking &gt; Other Linker Flag</strong>：</p>
<pre><code>-force_load $(SRCROOT)/Pods/TensorFlowLiteSelectTfOps/Frameworks/TensorFlowLiteSelectTfOps.framework/TensorFlowLiteSelectTfOps
</code></pre><p>
        <a data-fancybox="gallery" href="https://miro.medium.com/freeze/max/60/1*aKozvuHGTXbGcwiqEfUzJg.gif?q=20">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/freeze/max/60/1*aKozvuHGTXbGcwiqEfUzJg.gif?q=20" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/700/1*aKozvuHGTXbGcwiqEfUzJg.gif">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/700/1*aKozvuHGTXbGcwiqEfUzJg.gif" />
        </a>
    </p>
<p>添加强制加载命令</p>
<p>最后，<code>/ios</code>在终端上运行以下命令进入目录：</p>
<pre><code>$ flutter pub get
$ pod install
$ flutter clean
</code></pre><p>确保您已<strong>更新 CocoaPods</strong>。在<code>pod install</code>此期间可能会发出警告。</p>
<pre><code>[!] CocoaPods did not set the base configuration of your project because your project already has 
a custom config set. In order for CocoaPods integration to work at all, please either set the base 
configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` 
or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration
(`Flutter/Release.xcconfig`).
</code></pre><p>如果您在<code>pod install</code>命令后收到此警告，请将以下行添加到您的<code>ios/Flutter/Release.xcconfig</code>文件中并再次运行<code>pod install</code>：</p>
<pre><code>#include “Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig”
</code></pre><h1 id="加载和使用模型">加载和使用模型</h1>
<p>在您的<strong>initState() 方法上</strong>，您必须<strong>加载模型</strong>：</p>
<pre><code>TfliteAudio.loadModel(
    model: 'assets/soundclassifier.tflite',
    label: 'assets/labels.txt',
    numThreads: 1,
    isAsset: true);；
</code></pre><p>现在，我建议实施一种新方法来记录音频并对其进行分析。tflite_audio 包的**startAudioRecognition()**方法具有以下必须通过参数传递的参数：</p>
<ul>
<li><strong>numOfInferences</strong> — 指定将重复的推理次数</li>
<li><strong>inputType</strong> — 指定输入音频的类型</li>
<li><strong>sampleRate</strong> — 每秒样本数</li>
<li><strong>RecordingLength</strong> — 确定张量输入的大小</li>
<li><strong>bufferSize</strong> — 处理任何传入音频信号的时间量</li>
</ul>
<p>由于分类模型是 GTM 模型，因此您必须将音频识别的<strong>inputType</strong>指定为**&lsquo;rawAudio&rsquo;。**如果您使用自己的模型(decodedwav 模型)而不是 GTM 模型，则 inputType 必须是“decodedWav”。对于**sampleRate**，<a href="https://pub.dev/packages/tflite_audio">packages文档</a>上的推荐值是**16000 、 22050**或**44100**，将使用较高的值以提高准确性。该**recordingLength**值**必须等于输入张**和**缓冲区大小**应该是**recordingLenght值的一半**。</p>
<pre><code>void _recorder() {
    String recognition = &quot;&quot;;
    if (!_recording) {
      setState(() =&gt; _recording = true);
      result = TfliteAudio.startAudioRecognition(
        numOfInferences: 1,
        inputType: 'rawAudio',
        sampleRate: 44100,
        recordingLength: 44032,
        bufferSize: 22016,
      );
      result.listen((event) {
        recognition = event[&quot;recognitionResult&quot;];
      }).onDone(() {
        setState(() {
          _recording = false;
          _sound = recognition.split(&quot; &quot;)[1];
        });
      });
   }
  } 
</code></pre><p>此外，必须声明结果流变量：</p>
<pre><code>class _MyHomePageState extends State&lt;MyHomePage&gt; {
  String _sound = &quot;Press the button to start&quot;;
  bool _recording = false;
  Stream&lt;Map&lt;dynamic, dynamic&gt;&gt; result;
</code></pre><p>如果你想在执行时<strong>停止音频识别</strong>，你可以使用这个方法：</p>
<pre><code>TfliteAudio.stopAudioRecognition(); 
</code></pre><p>最后，应用程序可以使用了！😄 请注意，如前所述，该应用程序只能在 Android 和 iOS 物理设备上运行。如果你在 iOS 设备的部署过程中遇到一些问题，我推荐这个<a href="https://flutter.dev/docs/deployment/ios">文档</a>。另外，请注意，当您第一次在 iOS 设备上运行该应用程序时，它会崩溃，因为您必须信任它(详情<a href="https://flutter.dev/docs/deployment/ios">在此处</a>解释)。</p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/2160/1*2wEA54uAttc-h6EZAzXhvg.gif">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/2160/1*2wEA54uAttc-h6EZAzXhvg.gif" />
        </a>
    </p>
<p>
        <a data-fancybox="gallery" href="https://miro.medium.com/max/2160/1*OhOxEOV0JXMw4zeZ_PfQOA.gif">
            <img class="mx-auto" alt="img" src="https://miro.medium.com/max/2160/1*OhOxEOV0JXMw4zeZ_PfQOA.gif" />
        </a>
    </p>
<p>iOS(左)和 Android(右)设备中的应用程序预览</p>
<h1 id="代码">代码</h1>
<p>如果要查看完整代码：<a href="https://github.com/cmalbuquerque/audio_recognition_app">https</a> : <a href="https://github.com/cmalbuquerque/audio_recognition_app">//github.com/cmalbuquerque/audio_recognition_app</a></p>
<p>请查看我的<a href="https://github.com/cmalbuquerque">Github</a>个人资料！😉</p>
        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://luckly.work/">luckly</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://luckly.work/post/flutter_tips/Flutter%E9%9F%B3%E9%A2%91%E8%AF%86%E5%88%AB/">https://luckly.work/post/flutter_tips/Flutter%E9%9F%B3%E9%A2%91%E8%AF%86%E5%88%AB/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/post/flutter_tips/Flutter%E4%B8%80%E5%88%87%E7%9A%86widget%E4%BD%86%E6%98%AF%E4%B8%8D%E8%A6%81%E5%B0%86%E6%89%80%E6%9C%89%E4%B8%9C%E8%A5%BF%E6%94%BE%E5%85%A5%E4%B8%80%E4%B8%AAwidget/">Flutter一切皆widget但是不要将所有东西放入一个widget</a></li>
        
        <li><a href="/post/Flutter/flutter%E9%9D%A2%E8%AF%95%E9%A2%984%E4%B9%8B%E5%B8%B8%E8%A7%81%E5%BC%80%E5%8F%91%E9%97%AE%E9%A2%98/">Flutter面试题4之常见开发问题</a></li>
        
        <li><a href="/post/Flutter/flutter%E9%9D%A2%E8%AF%95%E9%A2%983%E4%B9%8B%E5%B8%B8%E8%A7%81%E5%BC%80%E5%8F%91%E9%97%AE%E9%A2%98/">Flutter面试题3之常见开发问题</a></li>
        
        <li><a href="/post/Flutter/flutter%E9%9D%A2%E8%AF%95%E9%A2%982%E4%B9%8B%E5%B8%B8%E8%A7%81%E5%BC%80%E5%8F%91%E9%97%AE%E9%A2%98/">Flutter面试题2之常见开发问题</a></li>
        
        <li><a href="/post/Flutter/flutter%E6%9E%B6%E6%9E%84-%E6%88%91%E7%9A%84provider%E5%AE%9E%E6%96%BD%E6%8C%87%E5%8D%97/">Flutter架构 我的provider实施指南</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='/tags/Flutter'>Flutter</a></li>
                
            </ul>
            
        </div>
    </article>
    
    

    
    
    <div class="post bg-white">
      <script src="https://utteranc.es/client.js"
            repo= "https://github.com/ITmxs/repo"
            issue-term="pathname"
            theme="github-light"
            crossorigin="anonymous"
            async>
      </script>
    </div>
    
</div>

                    <footer id="footer">
    <div>
        &copy; 2021 <a href="https://luckly.work/">早起的年轻人 By luckly</a>
        
        | <a rel="nofollow" target="_blank" href="http://beian.miit.gov.cn/">粤ICP备2021号-1</a>
        
    </div>
    <br />
    <div>
        <div class="github-badge">
            <a href="https://juejin.cn/user/3843548384077192" target="_black" rel="nofollow"><span class="badge-subject">Powered by</span><span class="badge-value bg-blue">掘金</span></a>
        </div>
        <div class="github-badge">
            <a href="https://space.bilibili.com/480883651" target="_black"><span class="badge-subject">Design by</span><span class="badge-value bg-brightgreen">早起的年轻人</span></a>
        </div>
        <div class="github-badge">
            <a href="https://cloud.tencent.com/developer/user/6702670" target="_black"><span class="badge-subject">Theme</span><span class="badge-value bg-yellowgreen">云社区</span></a>
        </div>
    </div>
</footer>


    
    <script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script><script src="https://cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/js/totop.js?v=0.0.0' async=""></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/js/douban.js'></script>
    <script src="/js/copy-to-clipboard.js"></script>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://luckly.work/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://luckly.work/">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9/" title="Nginx文件内容">Nginx文件内容</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/nginx%E6%9E%81%E7%AE%80%E6%95%99%E7%A8%8B/" title="Nginx极简教程">Nginx极简教程</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/nginx/%E5%8D%81%E5%88%86%E9%92%9F%E5%85%A5%E9%97%A8nginx/" title="十分钟入门Nginx">十分钟入门Nginx</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/go/Goland%E8%BF%9C%E7%A8%8B%E5%BC%80%E5%8F%91%E9%85%8D%E7%BD%AE/" title="Goland远程开发配置">Goland远程开发配置</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E8%AF%BB%E4%B9%A6/%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/" title="域名解析">域名解析</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/git/%E6%8F%90%E4%BA%A4%E8%BF%87%E7%A8%8B%E7%9C%81%E7%95%A5%E6%9F%90%E4%BA%9B%E6%96%87%E4%BB%B6/" title="提交过程省略某些文件">提交过程省略某些文件</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_DropdownButton%E7%A4%BA%E4%BE%8B/" title="Flutter_DropdownButton示例">Flutter_DropdownButton示例</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter_ExpansionPanelList%E5%92%8CExpansionPanelList.radio%E7%A4%BA%E4%BE%8B/" title="Flutter_ExpansionPanelList和ExpansionPanelList">Flutter_ExpansionPanelList和ExpansionPanelList</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/flutter_tips/Flutter%E5%BE%AE%E4%BF%A1%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E8%B7%B3%E5%9B%9EApp%E6%8C%87%E5%AE%9A%E9%A1%B5%E9%9D%A2/" title="Flutter微信分享链接跳回App指定页面">Flutter微信分享链接跳回App指定页面</a>
    </li>
    
    <li>
        <a href="https://luckly.work/post/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F/%E5%A4%96%E5%8C%85%E5%8F%AF%E8%83%BD%E7%9A%84%E9%97%AE%E9%A2%98/" title="外包可能的问题">外包可能的问题</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title"><a href='/categories/'>分类</a></h3>
<ul class="widget-list">
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (326)</a></li>
    
    <li><a href="https://luckly.work/categories/IT/">IT (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Kotlin/">Kotlin (2)</a></li>
    
    <li><a href="https://luckly.work/categories/Mysql/">Mysql (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (1)</a></li>
    
    <li><a href="https://luckly.work/categories/Vue/">Vue (6)</a></li>
    
    <li><a href="https://luckly.work/categories/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/android/">android (6)</a></li>
    
    <li><a href="https://luckly.work/categories/dart/">dart (96)</a></li>
    
    <li><a href="https://luckly.work/categories/Flutter/">Flutter (28)</a></li>
    
    <li><a href="https://luckly.work/categories/gin/">gin (25)</a></li>
    
    <li><a href="https://luckly.work/categories/git/">git (4)</a></li>
    
    <li><a href="https://luckly.work/categories/Go/">Go (102)</a></li>
    
    <li><a href="https://luckly.work/categories/gorm/">gorm (4)</a></li>
    
    <li><a href="https://luckly.work/categories/grpc/">grpc (1)</a></li>
    
    <li><a href="https://luckly.work/categories/html/">html (3)</a></li>
    
    <li><a href="https://luckly.work/categories/ios/">ios (1)</a></li>
    
    <li><a href="https://luckly.work/categories/linux/">linux (1)</a></li>
    
    <li><a href="https://luckly.work/categories/nginx/">nginx (6)</a></li>
    
    <li><a href="https://luckly.work/categories/python/">python (35)</a></li>
    
    <li><a href="https://luckly.work/categories/read/">读书笔记 (6)</a></li>
    
    <li><a href="https://luckly.work/categories/redis/">redis (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E5%8D%95/">书单 (8)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%B9%A6%E8%AF%84/">书评 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师 (19)</a></li>
    
    <li><a href="https://luckly.work/categories/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师 (25)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E5%88%99/">原则 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%9F%BA%E7%A1%80/">基础 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E5%BF%83%E8%AF%AD/">心语 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%8F%92%E4%BB%B6/">插件 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E6%95%99%E5%AD%A6/">教学 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%B2%BE%E8%BF%9B/">精进 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E7%BC%96%E7%A8%8B/">编程 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%99%9A%E5%B9%BB/">虚幻 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路 (2)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%91%E6%AD%A5/">跑步 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%B7%AF%E7%BA%BF/">路线 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学 (3)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%A1%B9%E7%9B%AE/">项目 (1)</a></li>
    
    <li><a href="https://luckly.work/categories/%E9%AD%85%E5%8A%9B/">魅力 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title"><a href='/tags/'>标签</a></h3>
<div class="tagcloud">
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/IT/">IT</a>
    
    <a href="https://luckly.work/tags/Kotlin/">Kotlin</a>
    
    <a href="https://luckly.work/tags/Mysql/">Mysql</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/Vue/">Vue</a>
    
    <a href="https://luckly.work/tags/YouTube%E8%A7%86%E9%A2%91%E4%B8%8B%E8%BD%BD/">YouTube视频下载</a>
    
    <a href="https://luckly.work/tags/android/">android</a>
    
    <a href="https://luckly.work/tags/dart/">dart</a>
    
    <a href="https://luckly.work/tags/flutter/">flutter</a>
    
    <a href="https://luckly.work/tags/gin/">gin</a>
    
    <a href="https://luckly.work/tags/git/">git</a>
    
    <a href="https://luckly.work/tags/go/">go</a>
    
    <a href="https://luckly.work/tags/gorm/">gorm</a>
    
    <a href="https://luckly.work/tags/grpc/">grpc</a>
    
    <a href="https://luckly.work/tags/html/">html</a>
    
    <a href="https://luckly.work/tags/ios/">ios</a>
    
    <a href="https://luckly.work/tags/linux/">linux</a>
    
    <a href="https://luckly.work/tags/nginx/">nginx</a>
    
    <a href="https://luckly.work/tags/python/">python</a>
    
    <a href="https://luckly.work/tags/redis/">redis</a>
    
    <a href="https://luckly.work/tags/%E4%B8%AA%E4%BA%BA%E8%B5%84%E6%96%99/">个人资料</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E5%8D%95/">书单</a>
    
    <a href="https://luckly.work/tags/%E4%B9%A6%E8%AF%84/">书评</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统管理师</a>
    
    <a href="https://luckly.work/tags/%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F%E9%A1%B9%E7%9B%AE%E7%AE%A1%E7%90%86%E5%B8%88/">信息系统项目管理师</a>
    
    <a href="https://luckly.work/tags/%E5%85%A5%E9%97%A8/">入门</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E5%88%99/">原则</a>
    
    <a href="https://luckly.work/tags/%E5%8E%9F%E7%94%9F%E9%80%9A%E8%AE%AF/">原生通讯</a>
    
    <a href="https://luckly.work/tags/%E5%9F%BA%E7%A1%80/">基础</a>
    
    <a href="https://luckly.work/tags/%E5%A4%8D%E5%88%A9%E6%95%88%E5%BA%94/">复利效应</a>
    
    <a href="https://luckly.work/tags/%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">安装教程</a>
    
    <a href="https://luckly.work/tags/%E5%B0%91%E6%9C%89%E4%BA%BA%E8%B5%B0%E7%9A%84%E8%B7%AF/">少有人走的路</a>
    
    <a href="https://luckly.work/tags/%E5%BF%83%E8%AF%AD/">心语</a>
    
    <a href="https://luckly.work/tags/%E6%8F%92%E4%BB%B6/">插件</a>
    
    <a href="https://luckly.work/tags/%E6%95%99%E5%AD%A6/">教学</a>
    
    <a href="https://luckly.work/tags/%E7%8E%8B%E9%98%B3%E6%98%8E/">王阳明</a>
    
    <a href="https://luckly.work/tags/%E7%94%B5%E5%AD%90%E4%B9%A6/">电子书</a>
    
    <a href="https://luckly.work/tags/%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95/">登陆表单</a>
    
    <a href="https://luckly.work/tags/%E7%A8%BB%E7%9B%9B%E5%92%8C%E5%A4%AB/">稻盛和夫</a>
    
    <a href="https://luckly.work/tags/%E7%A9%B7%E7%88%B8%E7%88%B8%E5%AF%8C%E7%88%B8%E7%88%B8/">穷爸爸富爸爸</a>
    
    <a href="https://luckly.work/tags/%E7%B2%BE%E8%BF%9B/">精进</a>
    
    <a href="https://luckly.work/tags/%E7%BC%96%E7%A8%8B/">编程</a>
    
    <a href="https://luckly.work/tags/%E8%99%9A%E5%B9%BB/">虚幻</a>
    
    <a href="https://luckly.work/tags/%E8%AF%97/">诗</a>
    
    <a href="https://luckly.work/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书笔记</a>
    
    <a href="https://luckly.work/tags/%E8%B4%A2%E5%8A%A1%E8%87%AA%E7%94%B1%E4%B9%8B%E8%B7%AF/">财务自由之路</a>
    
    <a href="https://luckly.work/tags/%E8%B7%91%E6%AD%A5/">跑步</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%94%B1%E4%BC%A0%E5%8F%82/">路由传参</a>
    
    <a href="https://luckly.work/tags/%E8%B7%AF%E7%BA%BF/">路线</a>
    
    <a href="https://luckly.work/tags/%E8%BD%AF%E4%BB%B6%E5%AE%9E%E6%96%BD/">软件实施</a>
    
    <a href="https://luckly.work/tags/%E9%80%9A%E8%AE%AF%E5%BD%95/">通讯录</a>
    
    <a href="https://luckly.work/tags/%E9%98%B3%E6%98%8E%E5%BF%83%E5%AD%A6/">阳明心学</a>
    
    <a href="https://luckly.work/tags/%E9%A1%B9%E7%9B%AE/">项目</a>
    
    <a href="https://luckly.work/tags/%E9%AD%85%E5%8A%9B/">魅力</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="http://www.topgoer.com/" title="枯藤">枯藤</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gorm.cn/zh_CN/docs/index.html" title="gorm">gorm</a>
        </li>
        
        <li>
            <a target="_blank" href="https://docs.python.org/zh-cn/3/tutorial/index.html" title="python">python</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.liwenzhou.com/" title="李文周">李文周的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://www.xbzweb.com/" title="小包子的博客">小包子的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://www.flysnow.org/" title="飞雪无情的博客">飞雪无情的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://sliverhorn.com/" title="sliverhorn的博客">sliverhorn的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="http://yuedu.baidu.com/ebook/14a722970740be1e640e9a3e" title="Android Gradle权威指南">Android Gradle权威指南</a>
        </li>
        
        <li>
            <a target="_blank" href="https://gesdh.cn/" title="小格子">格子导航</a>
        </li>
        
        <li>
            <a target="_blank" href="https://itachi.xyz/" title="阿林">itachi&#39;s Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://darjun.github.io/" title="大俊">大俊Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="https://geektutu.com/post/quick-golang.html" title="极客兔兔">极客兔兔Blog</a>
        </li>
        
        <li>
            <a target="_blank" href="http://zxfcumtcs.github.io/" title="赵雪峰">雪峰Blog</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://luckly.work/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
</body>

</html>